package com.example.controller;

import com.example.service.AsyncTaskService;
import com.example.task.thread.MyThread;
import com.example.util.MyKeyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/mykey")
public class MyKeyController {

    @Autowired
    private ThreadPoolTaskExecutor taskExecutor;

//    @Autowired
//    MyKeyUtil myKeyUtil;

    @Autowired
    AsyncTaskService AsyncTaskService;

    @RequestMapping(value = "/get")
    public String myKey() {
        taskExecutor.execute(new MyThread(AsyncTaskService));
        return "Hello";
    }

    @RequestMapping(value = "/thread")
    public String getThreadNum() {
        int activeCount = taskExecutor.getActiveCount();
        int corePoolSize = taskExecutor.getCorePoolSize();
        int maxPoolSize = taskExecutor.getMaxPoolSize();
        int poolSize = taskExecutor.getPoolSize();

        return "activeCount=" + activeCount + "</br>" + "corePoolSize=" + corePoolSize + "</br>"
                + "maxPoolSize="+maxPoolSize  + "</br>"  + "poolSize="+poolSize;

    }


}
